<template>
	<view>
		<rich-text class="richtxt" :nodes="content"></rich-text>
		<view class="footerbtn">
			<view class="btn" @click="download()"><image src="/static/index/wd.png" mode=""></image>文档下载</view>
			<view class="btn"><image src="/static/index/dayin.png"></image>文档打印</view>
		</view>
	</view>
</template>

<script>
	import { getcoursedirectory } from '@/api/live.js'
	import config from '@/config/config.js'
import toast from 'uview-ui/libs/function/toast';
	export default {
		data() {
			return {
				content:'',
				wdUrl:''
			};
		},
		onLoad(options) {
			this.init(options.id)
		},
		methods:{
			init(id){
				let that = this
				getcoursedirectory(id).then(res=>{
					that.wdUrl = config.baseUrl + '/uploads/' +  res.data.data.documentation
					that.content = res.data.data.content
				})
			},
			download(){
				let that = this
				uni.downloadFile({
					url: that.wdUrl,//文件的下载路径
					success(res) {
						//保存到本地
						uni.saveFile({
							tempFilePath: res.tempFilePath,//文件的临时路径
							success: function(res) {
								const savedFilePath = res.savedFilePath;
								// 打开文件
								uni.openDocument({
									filePath: savedFilePath,
									success: function(res) {
										// uni.hideLoading()
										toast('下载成功')
									},
									fail: function(res) {
										toast('下载失败')
									},
									complete: function(res) {
										// setTimeout(uni.hideLoading(), 4000)
									},
								});
							},
							fail: function(err) {	}
						});
					},
					fail(res) {}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
.footerbtn{
	width: 100vw;
	height: 96upx;
	line-height: 96upx;
	position: fixed;
	bottom: 0;
	display: flex;
	justify-content: space-around;
	.btn{
		>image{
			display: inline-block;
			width: 40upx;
			height: 40upx;
			vertical-align: middle;
		}
	}
}
.richtxt{
	padding: 0 20upx;
}
</style>
